package com.kaoshi;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/3/25 9:42
 * @description
 */
public class getNum {
    public static void main(String[] args) {
        int[] arr = new int[5];
        Scanner input = new Scanner(System.in);
        for (int i = 0; i < arr.length; i++) {
            System.out.print("请输入第"+(i+1)+"个整数:");
            arr[i] = input.nextInt();
        }
        System.out.println(Arrays.toString(arr));

        //统计比10大的数字个数
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]>10){
                count++;
            }
        }
        System.out.println("比10大的数字有"+count+"个");

        //输出最大最小值
        int max = 0,min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (max<arr[i]){
                max = arr[i];
            }
            if (min>arr[i]){
                min = arr[i];
            }
        }
        System.out.println("数组中最大值为："+max+
                ",数组中最小值为:"+min);

        //查询数组中是否存在该数字
        System.out.print("请输入要查询的数字：");
        int num = input.nextInt();
        String indexs = "";
        boolean flag = true;
        for (int i = 0; i < arr.length; i++) {
            if (num==arr[i]){
                indexs = indexs+i+" ";
                flag = false;
            }
        }
        if (flag){
            System.out.println("查无此数");
        }else {
            System.out.println("索引位置为"+indexs);
        }


        //冒泡排序
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if (arr[j]<arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        System.out.println("冒泡排序后");
        System.out.println(Arrays.toString(arr));
    }
}
